<?php
include_once('lib/config.inc.php');

$action = _g('a');
if(!in_array($action,array('add','view','as'))){
	show_error();
}
$db = new CPDO();
$post = _p('form');
if($post){
	$cate = _p('cate');
	$title = _p('title');
	$content = _p('content');
	$desc = _p('desc');
	if(!$cate || !$title || !$content){
		view($action);
	}else{
		$id = _g('i',0);
        if($id){
    		$codes = $db->get('select * from `cc_code` where id = ' . $id);
	    	if($codes){
		    	$sql = "update `cc_code` set `title` = '$title' , `content` = '$content', `cate` = '$cate', `desc` = '$desc' where `id` = $id";
		    	$db->update($sql);
            }
		}else{
			$sql = "insert into `cc_code` (`title`,`content`,`cate`,`desc`) values ('$title', '$content', '$cate','$desc')";
			$db->insert($sql);
		}
		redirect('/hive.php?a=view&i='.$id);
	}
}else{
	view($action);
}
?>
